<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="受益人名称" prop="syName">
        <el-input v-model="queryParams.syName" placeholder="请输入受益人名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名称" prop="xmName">
        <el-input v-model="queryParams.xmName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['guarantee:bidding:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="biddingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" prop="id" >
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务员" align="center" prop="userName" />
      <el-table-column label="受益人名称" align="center" prop="syName" />
      <el-table-column label="受益人类型" align="center" prop="syType" />
      <el-table-column label="项目名称" align="center" prop="xmName" />
      <el-table-column label="项目所在地省" align="center" prop="xmSheng" />
      <el-table-column label="项目所在地市" align="center" prop="xmShi" />
      <el-table-column label="项目所在地" align="center" prop="xmAddress" />
      <el-table-column label="项目类型" align="center" prop="xmType" />
      <el-table-column label="业绩" align="center" prop="yeji" />
      <el-table-column label="出函日期" align="center" prop="bhDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bhDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button    size="mini" type="text" icon="el-icon-edit" @click="handleCheckrow(scope.row)"
                        v-hasPermi="['guarantee:bidding:edit']">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!-- 添加或修改投标保函对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1360px" append-to-body>
      <el-form ref="form" :inline="true" :model="form" label-width="180px" >
        <!-- 基本信息 -->
        <el-divider content-position="left">基本信息</el-divider>
        <div>
          <el-form-item label="是否补录" prop="isBulu">
            <div class="label_txt">{{ form.isBulu }}</div>
          </el-form-item>
          <el-form-item label="受益人名称" prop="syName">
            <div class="label_txt">{{ form.syName }}</div>
          </el-form-item>
          <el-form-item label="受益人类型" prop="syType">
            <div class="label_txt">{{ form.syType }}</div>
          </el-form-item>
        </div>

        <div>
          <el-form-item label="项目名称" prop="xmName">
            <div class="label_txt">{{ form.xmName }}</div>
          </el-form-item>
          <el-form-item label="项目所在省市" prop="xmShengAndShi">
            <div class="label_txt">{{ form.xmSheng + '/' + form.xmShi }}</div>
          </el-form-item>
          <el-form-item label="项目所在地" prop="xmAddress">
            <div class="label_txt">{{ form.xmAddress }}</div>
          </el-form-item>
          <el-form-item label="项目类型" prop="xmType">
            <div class="label_txt">{{ form.xmType }}</div>
          </el-form-item>
          <el-form-item label="是否特殊项目" prop="xmSpecial">
            <div class="label_txt">{{ form.xmSpecial }}</div>
          </el-form-item>
          <el-form-item label="开标时间" prop="xmKbdate">
            <div class="label_txt">{{ form.xmKbdate }}</div>
          </el-form-item>
          <el-form-item label="投标有效期" prop="xmValidity">
            <div class="label_txt">{{ form.xmValidity }}</div>
          </el-form-item>
        </div>


        <div>
          <el-form-item label="项目的上传文件" prop="xmFileUrl">
            <file-upload class="disable_upload" v-model="form.xmFileUrl" />
          </el-form-item>
        </div>

        <!-- 企业信息 -->
        <template v-for="(item, index) in form.companyArr" >
          <el-divider class="b_divider_tit" content-position="left">
            <span class="divider_tit">企业信息</span>
          </el-divider>
          <!-- 基本信息 -->
          <el-divider class="s_divider_tit" content-position="left">基本信息</el-divider>
          <div class="bd_box">
            <el-form-item v-for="(ite, i) in item.xmNameLots" :key="i" label="标段"
                          :prop="'companyArr.' + index + '.xmNameLots.' + i">
              <div class="label_txt">{{ ite }}</div>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="企业名称" :prop="'companyArr.' + index + '.name'">
              <div class="label_txt">{{ item.name }}</div>
            </el-form-item>
            <el-form-item label="企业所在省市" :prop="'companyArr.' + index + '.qyShengAndShi'">
              <div class="label_txt">{{ item.sheng + '/' + item.shi }}</div>
            </el-form-item>
            <el-form-item label="企业地址" :prop="'companyArr.' + index + '.address'">
              <div class="label_txt">{{ item.address }}</div>
            </el-form-item>
            <el-form-item label="发票类型" :prop="'companyArr.' + index + '.fpType'">
              <div class="label_txt">{{ item.fpType }}</div>
            </el-form-item>
            <el-form-item label="发票名称" :prop="'companyArr.' + index + '.kpName'">
              <div class="label_txt">{{ item.kpName }}</div>
            </el-form-item>
            <el-form-item label="发票税号" :prop="'companyArr.' + index + '.kpNum'">
              <div class="label_txt">{{ item.kpNum }}</div>
            </el-form-item>
            <el-form-item label="发票电话" :prop="'companyArr.' + index + '.kpPhone'">
              <div class="label_txt">{{ item.kpPhone }}</div>
            </el-form-item>
            <el-form-item label="发票地址" :prop="'companyArr.' + index + '.kpAddress'">
              <div class="label_txt">{{ item.kpAddress }}</div>
            </el-form-item>
            <el-form-item label="发票开户行" :prop="'companyArr.' + index + '.kpBank'">
              <div class="label_txt">{{ item.kpBank }}</div>
            </el-form-item>
            <el-form-item label="发票开户账号" :prop="'companyArr.' + index + '.kpBankNum'">
              <div class="label_txt">{{ item.kpBankNum }}</div>
            </el-form-item>
            <el-form-item label="是否包邮" :prop="'companyArr.' + index + '.freeMail'">
              <div class="label_txt">{{ item.freeMail == '1' ? '是' : '否' }}</div>
            </el-form-item>
            <el-form-item label="邮寄地址" :prop="'companyArr.' + index + '.mailAdress'">
              <div class="label_txt">{{ item.mailAdress }}</div>
            </el-form-item>
            <el-form-item label="营业执照" :prop="'companyArr.' + index + '.yyzzUrl'">
              <file-upload  class="disable_upload" v-model="item.yyzzUrl" />
            </el-form-item>
          </div>

          <!-- 保函信息 -->
          <el-divider class="s_divider_tit" content-position="left">保函信息</el-divider>
          <div>
            <el-form-item label="出函类型" :prop="'companyArr.' + index + '.bhType'">
              <div class="label_txt">{{ item.bhType }}</div>
            </el-form-item>
            <el-form-item label="出函机构及对接人" :prop="'companyArr.' + index + '.bhJigou'">
              <div class="label_txt">{{ getBLetterObj(item.bhJigou).institution }} ({{ getBLetterObj(item.bhJigou).name }})</div>
            </el-form-item>
            <el-form-item label="保函金额" :prop="'companyArr.' + index + '.bhMoney'">
              <div class="label_txt">{{ item.bhMoney }}</div>
            </el-form-item>
            <el-form-item label="保函有效期" :prop="'companyArr.' + index + '.bhValidity'">
              <div class="label_txt">{{ item.bhValidity }}</div>
            </el-form-item>
            <el-form-item label="特殊要求" :prop="'companyArr.' + index + '.bhNotes'">
              <div class="label_txt">{{ item.bhNotes }}</div>
            </el-form-item>
            <el-form-item label="保函格式" :prop="'companyArr.' + index + '.bhFormat'">
              <div class="label_txt">{{ item.bhFormat }}</div>
            </el-form-item>

            <el-form-item label="保函文件" :prop="'companyArr.' + index + '.bhUrl'">
              <file-upload   v-model="item.bhUrl" />
            </el-form-item>
          </div>

        </template>

        <!-- 运营 -->
        <el-divider content-position="left">运营</el-divider>

        <el-form-item label="受理意见" prop="acceptanceOpinion">
          <div class="label_txt">{{ form.acceptanceOpinion }}</div>
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <div class="label_txt">{{ form.price }}</div>
        </el-form-item>
        <el-form-item label="特殊备注" prop="specialRemark">
          <div class="label_txt">{{ form.specialRemark }}</div>
        </el-form-item>
        <el-form-item label="资料包是否合格" prop="contractHg">
          <div class="label_txt">{{ form.contractHg }}</div>
        </el-form-item>
        <el-form-item label="补充文件描述" prop="supplyRemark">
          <div class="label_txt">{{ form.supplyRemark }}</div>
        </el-form-item>
        <el-form-item label="总费用" prop="totalMoney">
          <div class="label_txt">{{ form.totalMoney }}</div>
        </el-form-item>
        <el-form-item label="银行成本" prop="bankMoney">
          <div class="label_txt">{{ form.bankMoney }}</div>
        </el-form-item>
        <el-form-item label="银行账户" prop="bankAccount">
          <div class="label_txt">{{ form.bankAccount }}</div>
        </el-form-item>
        <el-form-item label="是否收到" prop="bankSf">
          <div class="label_txt">{{ form.bankSf }}</div>
        </el-form-item>
        <el-form-item label="银行成本2" prop="bankMoney2">
          <div class="label_txt">{{ form.bankMoney2 }}</div>
        </el-form-item>
        <el-form-item label="银行账户2" prop="bankAccount2">
          <div class="label_txt">{{ form.bankAccount2 }}</div>
        </el-form-item>
        <el-form-item label="是否收到2" prop="bankSf2">
          <div class="label_txt">{{ form.bankSf2 }}</div>
        </el-form-item>
        <el-form-item label="返润" prop="fanMoney">
          <div class="label_txt">{{ form.fanMoney }}</div>
        </el-form-item>
        <el-form-item label="扣税" prop="taxMoney">
          <div class="label_txt">{{ form.taxMoney }}</div>
        </el-form-item>
        <el-form-item label="业绩" prop="yeji">
          <div class="label_txt">{{ form.yeji }}</div>
        </el-form-item>
        <el-form-item label="是否开票" prop="sfKp">
          <div class="label_txt">{{ form.sfKp }}</div>
        </el-form-item>
        <el-form-item label="出函日期" prop="bhDate">
          <div class="label_txt">{{ form.bhDate }}</div>
        </el-form-item>
        <el-form-item label="邮寄单号" prop="mailNum">
          <div class="label_txt">{{ form.mailNum }}</div>
        </el-form-item>
        <el-form-item label="补充资料" prop="supplyUrl">
          <file-upload  class="disable_upload" v-model="form.supplyUrl" />
        </el-form-item>
        <el-form-item label="签约资料包" prop="contractData">
          <file-upload class="disable_upload" v-model="form.contractData" />
        </el-form-item>

        <!-- 审核信息 -->
        <el-divider content-position="left">审核信息</el-divider>
        <div>
          <el-form-item label="审核状态:">
            <el-radio-group  prop v-model="form.checkStatus">
              <el-radio :label="12">通过</el-radio>
              <el-radio :label="-1">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核意见" prop="checkMind" :rules="{ required: true, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.checkMind" placeholder="请输入审核意见" />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  yyHList,
  getBidding,
  yyHSave
} from "@/api/guarantee/biddingCheck";
import { pcTextArr } from "element-china-area-data";
import {getBLetterList} from "@/api/guarantee/letter";

export default {
  name: "Bidding",
  data() {
    return {
      // 省市数据
      areaData: pcTextArr,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      bLetters:[],
      // 子表选中数据
      checkedBBiddingQy: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投标保函表格数据
      biddingList: [],
      // 投标保函-企业信息表格数据
      bBiddingQyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        status: null,
        syName: null,
        syType: null,
        xmName: null,
        xmSheng: null,
        xmShi: null,
      },
      // 表单参数
      form: {},
      // 表单参数
    };
  },
  created() {
    this.getList();
    this.getBLetters();
  },
  methods: {
    getBLetters(){
      getBLetterList().then(response => {
        this.bLetters = response.data;
      });
    },
    getBLetterObj(id){
      if(id && this.bLetters.length>0){
        return  this.bLetters.filter(item => item.id == id)[0]
      }else{
        return ''
      }
    },
    /** 查询投标保函列表 */
    getList() {
      this.loading = true;
      yyHList(this.queryParams).then(response => {
        this.biddingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        isBulu: null,
        userId: null,
        status: null,
        syName: null,
        syType: null,
        xmName: null,
        xmSheng: null,
        xmShi: null,
        xmAddress: null,
        xmType: null,
        xmSpecial: null,
        xmSpecialName: null,
        xmKbdate: null,
        xmValidity: null,
        xmFileUrl: null,

        companyArr: [{
          xmNameLots: [''],
          // 合作方费用显示
          fkHzShow: false,
          // qyName: null,
          // qyId: null,
          // qyShengAndShi: null,
          // qySheng: null,
          // qyShi: null,
          // qyAddress: null,
        }],
        acceptanceOpinion: null,
        price: null,
        supplyUrl: null,
        specialRemark: null,
        contractData: null,
        contractHg: null,
        supplyRemark: null,
        totalMoney: null,
        bankMoney: null,
        bankAccount: null,
        bankSf: null,
        bankMoney2: null,
        bankAccount2: null,
        bankSf2: null,
        fanMoney: null,
        taxMoney: null,
        yeji: null,
        sfKp: null,
        bhDate: null,
        mailNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        checkStatus: null,
        checkMind: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 审核按钮操作 */
    handleCheckrow(row) {
      this.reset();
      const id = row.id || this.ids
      getBidding(id).then(response => {
        this.form = response.data;
        this.bBiddingQyList = response.data.bBiddingQyList;
        this.form.xmShengAndShi = [this.form.xmSheng, this.form.xmShi]
        this.form.companyArr.forEach(element => {
          element.qyShengAndShi = [element.sheng, element.shi]
          if (element.fkHzShifou === '有') {
            element.fkHzShow = true
          } else {
            element.fkHzShow = false
          }
        });
        this.open = true;
        this.title = "审核投标保函";
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          yyHSave(this.form).then(response => {
            this.$modal.msgSuccess("保存成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 复选框选中数据 */
    handleBBiddingQySelectionChange(selection) {
      this.checkedBBiddingQy = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('guarantee/bidding/export', {
        ...this.queryParams
      }, `bidding_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>

<style lang="scss" scoped>
.my_select {
  width: 204px;
}

.my_picker {
  width: 204px;
}

.lotInput {
  width: 150px;
  margin-right: 10px;
}

.bd_box {
  display: flex;
  flex-wrap: wrap;
}

.divider_tit {
  margin-right: 10px;
}

.b_divider_tit {
  margin-bottom: 50px;
}

.s_divider_tit {
  width: 94%;
  margin: 24px 20px;
}

.disable_upload ::v-deep .el-upload--picture-card,.disable_upload ::v-deep .upload-file-uploader, .disable_upload::v-deep .ele-upload-list__item-content-action{
  display: none
}
.label_txt {
  width: 204px
}
</style>

